<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <th:block th:include="include :: header('场景管理')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
    <style>
        .treetable-table .btn {
            margin: 0 2px;
        }

        .modal-dialog .control-label {
            margin: 6px 0 2px 0;
        }

        .modal .dept-view,
        .modal .sence-view {
            display: none;
        }

        .modal-dept .dept-view {
            display: block;
        }

        .modal-sence .sence-view {
            display: block;
        }

        .modal {
            width: 100%;
            height: 100%;
        }

        .modal .item-wrap {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }

        .modal .item-wrap .item-key {
            width: 70px;
            text-align: right;
            padding-right: 5px;
        }
    </style>
</head>

<body class="gray-bg">


    <!-- <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 组织机构
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理部门"><i
                            class="fa fa-edit"></i></a>
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                            class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                            class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i
                            class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div> -->

    <div class="ui-layout-center">
        <div class="container-div">
            <!-- 表单查询条件 -->
            <!-- <form id="scene-form">
                <input type="hidden" id="ejdwId" name="ejdwId">
                <input type="hidden" id="dw_3_id" name="dw_3_id">
                <input type="hidden" id="dw_4_id" name="dw_4_id">
                <input type="hidden" id="dw_5_id" name="dw_5_id">
                <input type="hidden" id="sceneId" name="sceneId">
            </form> -->
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                <input type="hidden" id="sceneId" name="sceneId">
                            </li>
                            <li style="display: flex;">
                                <label style="width: 70px;">请选择机构:</label>
                                <select name="bmId" id="dev_azdw1_select1" class="first form-control azdw-select1"
                                    data-index="1" style="width: 95px;"></select>
                            </li>
                            <li>
                                <select name="zyqId" id="dev_azdw2_select1" class="second form-control azdw-select1"
                                    data-index="2" style="width: 95px;"></select>
                            </li>
                            <li>
                                <select name="dw_3_id" id="dev_azdw3_select1" class="third form-control azdw-select1"
                                    data-index="3" style="width: 95px;"></select>
                            </li>
                            <li style="display: flex;">
                                <label>场景名称:</label>
                                <input type="text" id="sceneName" name="sceneName" placeholder="请输入场景名称">
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar1" role="group">
                <a class='btn btn-success' href='javascript:;' onclick='deptAddScene("dept")' title="新增场景">
                    <i class="fa fa-plus"></i>
                    <span>新增场景</span>
                </a>
            </div>
            <!-- 右侧场景表格 -->
            <div class="col-sm-12 select-table table-striped">
                <!-- 这是表格列表显示 -->
                <!-- <table id="bootstrap-table"></table> -->

                <!--这是表格树，列表显示-->
                <table id="bootstrap-tree-table"></table>
            </div>

        </div>
    </div>

    <!-- 这是编辑场景的弹框 -->
    <div class="modal" id="editor-scene-dialog" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">修改场景名称</h4>
                </div>

                <div class="modal-body">
                    <input type="hidden" name="sceneId" id="current-scene-id" value="" />
                    <div class="control-label">场景名称：</div>
                    <div class="input-wrap">
                        <input class="form-control" type="text" name="sceneName" id="new-scene-name"
                            placeholder="请输入新的场景名称" maxlength="30" />
                    </div>
                    <div class="control-label">当前的场景名称：</div>
                    <div class="input-wrap">
                        <input class="form-control" readonly="true" type="text" id="current-scene-name" value="" />
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitChangeSceneInfo()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 这是查看详情点位的列表 -->
    <div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <small class="font-bold">数据点位列表
                </div>
                <div class="modal-body">
                    <form id="scene-form">
                        <input type="hidden" id="sceneId" name="sceneId" />
                    </form>
                    <div class="btn-group-sm" id="toolbar" role="group">
                        <a class='btn btn-success' href='javascript:;' onclick='addScenePoint()' title="新增">
                            <i class="fa fa-plus"></i>
                            <span>新增采集数据点位</span>
                        </a>
                    </div>
                    <!-- 右侧场景表格 -->
                    <div class="col-sm-12 select-table table-point">
                        <!-- 这是表格列表显示 -->
                        <table id="positionTable"></table>
                    </div>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal" id="close">关闭</button>
                    <button type="button" class="btn btn-primary" id="close">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 这是场景下新增采集数据点的弹框 -->
    <div class="modal " id="add-point-dialog" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">新增采集数据点</h4>
                </div>

                <div class="modal-body">
                    <div class="item-wrap">
                        <span class="item-key">采集数据点:</span>
                        <select name="pointId" id="point-select" style="width:200px" class="form-control"></select>
                    </div>
                    <div class="item-wrap">
                        <span class="item-key">上限值:</span>
                        <input type="text" class="form-control" style="width:200px" name="upperLimit" id="upperLimit">
                    </div>
                    <div class="item-wrap ">
                        <span class="item-key">下限值:</span>
                        <input type="text" class="form-control" style="width:200px" name="lowerLimit" id="lowerLimit">
                    </div>

                    <div id="element2" class="item-wrap">
                        <span class="item-key">安装点位:</span>
                        <select name="dev_azdw1_id" id="dev_azdw1_select" class="first form-control azdw-select"
                            data-index="1" style="width: 95px;"></select>
                        <select name="dev_azdw2_id" id="dev_azdw2_select" class="second form-control azdw-select"
                            data-index="2" style="width: 95px;"></select>
                        <select name="dev_azdw3_id" id="dev_azdw3_select" class="third form-control azdw-select"
                            data-index="3" style="width: 95px;"></select>
                        <select name="dev_azdw4_id" id="dev_azdw4_select" class="fourth form-control azdw-select"
                            data-index="4" style="width: 95px;"></select>
                        <select name="dev_azdw5_id" id="dev_azdw5_select" class="fifth form-control azdw-select"
                            data-index="5" style="width: 95px;"></select>
                    </div>


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitAddScenePoint()">保存</button>
                </div>
            </div>
        </div>
    </div>


    <!-- 这是编辑监测点的弹框 -->
    <div class="modal " id="editor-point-dialog" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">修改采集监测点名称</h4>
                </div>

                <div class="modal-body">
                    <input type="hidden" name="sceneId" id="current-point-id" value="" />
                    <div class="control-label">采集监测点名称：</div>
                    <div class="input-wrap">
                        <input class="form-control" type="text" name="sceneName" id="new-point-name"
                            placeholder="请输入新的名称" />
                    </div>
                    <div class="control-label">当前的采集监测点名称：</div>
                    <div class="input-wrap">
                        <input class="form-control" readonly="true" type="text" id="current-point-name" value="" />
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitChangePointInfo()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 这是新增场景的弹框 -->
    <div class="modal " id="add-scene-dialog" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">添加场景</h4>
                </div>

                <div class="modal-body">
                    <div class="control-label">新增场景名称：</div>
                    <div class="input-wrap">
                        <input class="form-control" type="text" name="sceneName" id="add-scene-name"
                            placeholder="请输入新的场景名称" maxlength="30" />
                    </div>

                    <!-- 所属单位 -->
                    <!-- <div class="control-label dept-view">所属单位名称：</div>
                    <div class="input-wrap">
                        <input class="form-control readonly-input dept-view" readonly="true" type="text"
                            id="src-dept-name" value="" />
                            <label style="width: 70px;">请选择机构:</label>
                        <select name="dw_1_id" id="dev_azdw1_select2" class="first form-control azdw-select1"
                            data-index="1" style="width: 95px;"></select>
                        <select name="ejdwId" id="dev_azdw2_select2" class="second form-control azdw-select1"
                            data-index="2" style="width: 95px;"></select>
                        <select name="dw_3_id" id="dev_azdw3_select2" class="third form-control azdw-select1"
                            data-index="3" style="width: 95px;"></select>
                    </div> -->
                    <div class="control-label">请选择机构:</div>
                    <div id="element2" class="item-wrap">
                        <!-- <input class="form-control readonly-input dept-view" readonly="true" type="text"
                        id="src-dept-name" value="" /> -->
                        <!-- <label style="width: 70px;"></label> -->
                        <select name="dw_1_id" id="dev_azdw1_select2" class="first form-control azdw-select2"
                            data-index="1" style="width: 95px;"></select>
                        <select name="ejdwId" id="dev_azdw2_select2" class="second form-control azdw-select2"
                            data-index="2" style="width: 95px;margin-left: 10px;margin-right: 10px;"></select>
                        <select name="dw_3_id" id="dev_azdw3_select2" class="third form-control azdw-select2"
                            data-index="3" style="width: 95px;"></select>
                    </div>

                    <!-- 所属场景 -->
                    <!-- <div class="control-label sence-view">所属场景名称：</div>
                    <div class="input-wrap">
                        <input class="form-control readonly-input sence-view" readonly="true" type="text"
                            id="src-scene-name" value="" />
                    </div> -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="submitAddScene()">保存</button>
                </div>
            </div>
        </div>
    </div>



    <!-- 底部静态引入 -->
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:user:edit') }]];
        var removeFlag = [[${@permission.hasPermi('system:user:remove') }]];
        var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd') }]];
        var prefix = ctx + "youtianNew/sceneManagement";
        var checkTreeInfo = null;// 选中的左侧树的节点信息
        var checkSceneInfo = null; // 选中的场景信息
        var checkSceneTreeInfo = null;// 选中的左侧树的场景节点信息
        var bmName = null; //新增组织机构的以及名称
        var zyqName = null;//作业区名称
        var dw_3_name = null ;//三级名称
        // 定义右侧树表格查询参数对象
        /*var treeTableAjaxParams = {
                pageNum: 1,
                pageSize: 1000,
                ejdwId :'',
                dw_3_id :'',
                dw_4_id :'',deptAddScene
                dw_5_id :''
        } */
        // 定义右侧树表格查询参数对象
        var treeTableAjaxParams = {
            pageNum: 1,
            pageSize: 1001
        }

        $(function () {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                console.log('toTop 22 ========================= ')
                var opt = {
                    win: $('.ui-layout-center'),
                    doc: $('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            // 查询场景左侧树
            queryDeptTree();

            // 查询场景表格列表
            querySceneList();
            initAZDWselect();
            initAZDWselect1();
            initAZDWselect2();
            // 选择安装点位 select 下拉框的时候触发方法
            $('.azdw-select').change(function (e) {
                // $('.azdw-select').val("");
                var getSelectIndex = $(this).attr("data-index") || 1;
                var maxSelectIndex = 6;
                var nextSelectIndex = Number(getSelectIndex) + 1;
                let startIndex = getSelectIndex;
                while (startIndex < maxSelectIndex) {
                    startIndex++;
                    $(`#dev_azdw${startIndex}_select`).val("").text("请选择")
                }
                // 获取下一级select 下拉框的数据，只有存在下一级的时候，在需要调用设置 option 方法
                if (nextSelectIndex < maxSelectIndex) {
                    initAZDWselect(nextSelectIndex);
                }
                // 调用根据条件筛选监测点
                queryPointSelect();
            })
            
            $('.azdw-select1').change(function (e) {
                console.log(` change e ============================= `)
                console.log(e)
                console.log($(this))
               
                // $('.azdw-select').val("");
                var getSelectIndex = $(this).attr("data-index") || 1;
                var maxSelectIndex = 6;
                var nextSelectIndex = Number(getSelectIndex) + 1;
                let startIndex = getSelectIndex;
                while (startIndex < maxSelectIndex) {
                    startIndex++;
                    $(`#dev_azdw${startIndex}_select`).val("").text("请选择")
                }
                // 获取下一级select 下拉框的数据，只有存在下一级的时候，在需要调用设置 option 方法
                if (nextSelectIndex < maxSelectIndex) {
                    initAZDWselect1(nextSelectIndex);
                }
                // 调用根据条件筛选监测点
                queryPointSelect1();
            })
            //新增的下拉框
            $('.azdw-select2').change(function (e) {
                console.log(` change e ============================= `)
                console.log(e)
                console.log($(this).text())
                console.log( $("#dev_azdw1_select2").find("option:selected").text());
                bmName = $("#dev_azdw1_select2").find("option:selected").text();
                zyqName = $("#dev_azdw2_select2").find("option:selected").text()
                dw_3_name = $("#dev_azdw3_select2").find("option:selected").text()
                console.log(bmName,zyqName,dw_3_name);
                // $('.azdw-select').val("");
                var getSelectIndex = $(this).attr("data-index") || 1;
                var maxSelectIndex = 6;
                var nextSelectIndex = Number(getSelectIndex) + 1;
                let startIndex = getSelectIndex;
                while (startIndex < maxSelectIndex) {
                    startIndex++;
                    $(`#dev_azdw${startIndex}_select`).val("").text("请选择")
                }
                // 获取下一级select 下拉框的数据，只有存在下一级的时候，在需要调用设置 option 方法
                if (nextSelectIndex < maxSelectIndex) {
                    initAZDWselect2(nextSelectIndex);
                }
                // 调用根据条件筛选监测点
                queryPointSelect2();
            })
            // 选择完检测点之后，需要根据点击设置上下限的值
            $("#point-select").change(function (e) {
                console.log(' point-select e ========================== ')
                console.log(e)
                console.log('html=> ' + $(this).find("option:selected").html())
                var $checkOption = $(this).find("option:selected");
                var getLower = "";
                var getUpper = "";
                if ($checkOption) {
                    getLower = $checkOption.attr("data-lower");
                    getUpper = $checkOption.attr("data-upper");
                }
                $("#upperLimit").val(getLower == "null" ? "" : getUpper)
                $("#lowerLimit").val(getUpper == "null" ? "" : getLower)
            })
        });

        function querySceneList() {
            // url: `/youtian/scene-category/list`,
            console.log(`querySceneList 3333   ctx : ${ctx}`)
            console.log(`treeTableAjaxParams 444 1001 去掉分页 ==================== `)
            console.log(treeTableAjaxParams)
            var options = {
                // url: prefix + "/list",
                url: "/youtian/scene-category/list",
                method: 'get',
                // data:dataRow,
                expandAll: false,
                expandFirst: false,
                toolbar: 'toolbar1',
                code: "sceneId",
                parentCode: "parentId",
                uniqueId: "sceneId",
                ajaxParams: treeTableAjaxParams,
                // pagination: true,
                // showSearch: false,
                columns: [
                    {
                        field: 'selectItem',
                        width: '60',
                        widthUnit: 'px',
                        align: "center",
                        radio: true
                    },
                    {
                        field: 'sceneName',
                        title: '场景名称'
                    },
                    // {
                    //     field: 'sceneId',
                    //     width: '100',
                    //     widthUnit: 'px',
                    //     align: "center",
                    //     title: '场景ID'
                    // },
                    {
                        field: 'bmName',
                        title: '二级单位'
                    },
                    {
                        field: 'zyqName',
                        title: '所属区'
                    },
                    {
                        field: 'dw_3_name',
                        title: '所属站'
                    },

                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var rowJson = JSON.stringify(row);
                            var actions = [];
                            actions.push(`<a class='btn btn-success btn-xs' href='javascript:;' onclick='sceneAddScene(${rowJson})' title="新增"><i class="fa fa-plus"></i><span>点位详情</span></a>`)
                            // }
                            actions.push(`<a class='btn btn-primary btn-xs' href='javascript:;' onclick='showEditorDialog(${rowJson})' title="编辑"><i class='fa fa-edit'></i><span>编辑</span></a>`)
                            actions.push(`<a class="btn btn-danger btn-xs" href="javascript:;" onclick="deleteScene('${row.sceneId}','${row.sceneName}')" title="删除"><i class="fa fa-remove"></i><span>删除</span></a>`)
                            return actions.join('');
                        }
                    }]
            }
            //初始化树表格
            $.treeTable.init(options);
        }
        // 请求加载左侧树方法
        function queryDeptTree() {
            // var url = ctx + "system/dept/treeData";
            // var url = ctx + "gzmx_scdw/gzmx_scdw/tree"
            var url = "/gzmx_scdw/gzmx_scdw/temlateTreeDataNew";

            // 默认配置，只能 get 请求
            var options = {
                url: url,
                expandLevel: 2,
                onClick: deptOnClick
            };
            // let ab = $.tree.init( $('#tree'), options,zNodes);
            $.tree.init(options);
        }
        function setTreeTableParams(params) {
            console.log(` setTreeTableParams params ===  `)
            console.log(params)
            params = params ? params : {}
            treeTableAjaxParams = Object.assign(treeTableAjaxParams, params);
            // 调用查询方法
            querySceneList();
        }
        // 点击左侧树，触发查询方法
        function deptOnClick(event, treeId, treeNode) {
            console.log('event, treeId, treeNode 333 ======= ')
            console.log(event, treeId, treeNode)
            checkTreeInfo = treeNode;

            var getLevel = treeNode.level;
            var getId = treeNode.id // 对当前id
            var getpId = treeNode.pId // 对应的 父 id
            var ID = getId.toString().split('3832000000');
            var SceID;
            SceID = ID[ID.length - 1];
            console.log(SceID);
            $('#sceneId').val(SceID)
            console.log(ID);
            var initKey = {
                "2": "ejdwId",
                "3": "dw_3_id",
                "4": "dw_4_id",
                "5": "dw_5_id"
            }
            // 重新设置隐藏from 表单隐藏域的值
            for (const idKey in initKey) {
                var idName = initKey[idKey];
                $(`#${idName}`).val('');
                if (idKey == getLevel) {
                    $(`#${idName}`).val(getId);
                }
            }
            //调用查询方法
            $.treeTable.search();
        }

        // 点击右侧表格上方的新增场景按钮，在左侧选中数下新增新的场景
        function deptAddScene(jsonObj) {
            $('#add-scene-dialog').removeClass("modal-dept modal-sence")
            $("#add-scene-name").val("");
            // 如果是字符串，则说明是在部门下新增场景
            // if (typeof jsonObj == "string") {
            //     console.log('左侧树下新增~')
            //     // 2、 左侧树下，添加新场景
            //     var msg = ""
            //     if (!checkTreeInfo) {
            //         msg = "请您先选中左侧菜单，再添加新的场景~";
            //     }
            //     //
            //     if (checkTreeInfo && checkTreeInfo.level < 2) {
            //         msg = "只能在末层级，才能添加场景";
            //     }
            //     if (msg) {
            //         $.modal.msgError(msg);
            //         return;
            //     }
            //     $('#src-dept-name').val(checkTreeInfo.name);
            // }
            $('#add-scene-dialog').addClass("modal-dept").modal('show');
        }

        // 点击右侧表格查看详情按钮，在场景下新增新的场景
        function sceneAddScene(jsonObj) {
            checkSceneInfo = jsonObj;
            checkSceneTreeInfo = jsonObj
            let id = checkSceneTreeInfo.sceneId
            console.log(checkSceneTreeInfo);
            $('#sceneId').val(id)
            queryScenePointList()
            $('#myModal6').modal('show');
            // }
        }

        $('#close').on('click', function () {
            $.table.destroy("positionTable");
            $('#myModal6').modal('hide');
        })

        //新增点位保存
        function addScenePoint() {
            console.log('左侧树下新增~')
            // 2、 左侧树下，添加新场景
            var msg = ""
            /*if(checkSceneTreeInfo&&checkSceneTreeInfo.level<3){
                msg = "只能在末层级，才能添加监测点";
            }*/
            if (msg) {
                $.modal.msgError(msg);
                return;
            }
            // 每次显示都需要重置，下拉框的内容, 重置完之后在显示弹框
            $('#point-select').val("")
            $('.azdw-select').val("")
            $("#upperLimit").val("")
            $("#lowerLimit").val("")
            // 展示添加监测点弹框
            $('#add-point-dialog').modal('show');
        }

        // 场景下新增采集监测点方法（发送请求）
        function submitAddScenePoint() {
            var getValue = $.trim($('#point-select').val());
            var getlowerLimit = $.trim($('#lowerLimit').val());
            var getupperLimit = $.trim($('#upperLimit').val());
            if (getValue == '') {
                $.modal.msgError("请选择新增的监测点");
                return
            }
            let params = {
                "sceneId": checkSceneTreeInfo.sceneId,
                "pointId": getValue,
                "upperLimit": getupperLimit,
                "lowerLimit": getlowerLimit,
            }
            console.log(" data params 22 ==== ");
            console.log(params);
            $.ajax({
                method: "post",
                url: "/youtian/scene-point",
                data: JSON.stringify( params ),
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    if (res.msg) {
                        $.modal.msgSuccess(res.msg);
                    }
                    // 提交成功，刷新表格，并把input框里的值，清空。
                    if (res.code == 0) {
                        $.table.destroy();
                        $('#myModal6').modal('hide');
                        $('#add-point-dialog').modal('hide')
                        queryPointSelect()
                    }
                }
            });
        }

        function queryScenePointList() {
            var options = {
                id: 'positionTable',
                url: `/youtian/scene-category/scencePointlist`,
                method: 'get',
                showSearch: false,
                showRefresh: false,
                showColumns: false,
                showToggle: false,
                sortable: false, // 不使用排序
                // rowStyle:onRowStyle,// 根据条件渲染表格的行样式
                columns: [
                    /*{
                        field: 'selectItem',
                        width: '60',
                        widthUnit: 'px',
                        align: "center",
                        radio: true
                    },*/
                    {
                        field: 'pointName',
                        title: '采集数据点位',
                        align: "center"
                    },
                    {
                        field: 'sceneName',
                        title: '所属区',
                        align: "center"
                    },
                    {
                        field: 'deptName',
                        title: '所属单位',
                        align: "center"
                    },
                    {
                        field: 'dataState',
                        title: '状态',
                        align: "center",
                        formatter: function (value, row, index) {
                            if ($.trim(value) == "正常") {
                                return `<span style='color: #f00; font-weight: bold;'>${value}</span>`
                            }
                            return value
                        }
                    },
                    {
                        field: 'lowerLimit',
                        title: '下限',
                        align: "center"
                    },
                    {
                        field: 'upperLimit',
                        title: '上限',
                        align: "center"
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var rowJson = JSON.stringify(row);
                            // console.log(`rowJson : ${rowJson}`)
                            var actions = [];
                            actions.push(`<a class='btn btn-primary btn-xs' href='javascript:;' onclick='editPoint(${rowJson})' title="编辑"><i class='fa fa-edit'></i><span>编辑</span></a>`)
                            actions.push(`<a class="btn btn-danger btn-xs" href="javascript:;" onclick='deletePoint(${rowJson})' title='删除'><i class="fa fa-remove"></i><span>删除</span></a>`)
                            return actions.join('');
                        }
                    }
                ]
            }
            //初始化监测点表格
            $.table.init(options);
        }



        // 新增场景方法
        function submitAddScene() {
            var getName = $.trim($('#add-scene-name').val());
            if (getName == '') {
                console.log(`getName : ${getName}`)
                $.modal.msgError("请输入新增场景名称");
                return
            }
            if($('#dev_azdw3_select2').val() == ''){
                return $.modal.msg('请选择组织机构的第三级')
            }
            // 发送新增请求
            let postParams = {
                sceneName: getName,
                // parentId:0,
                // bmName:bmName,
                // zyqName:zyqName,
                // dw_3_name:dw_3_name,
                // bmId:$('#dev_azdw1_select2').val(),
                // zyqId:$('#dev_azdw2_select2').val(),
                // dw_3_id:$('#dev_azdw3_select2').val(),
                // sceneId:$('#dev_azdw3_select2').val()
            };
            // 这些参数是在场景下新增场景。， 反之则是在左侧树下新增场景
            if ($("#add-scene-dialog").hasClass('modal-sence')) {
                postParams.parentId = checkSceneInfo.sceneId;
                postParams.ejdwId = checkSceneInfo.ejdwId;
                postParams.ejdwName = checkSceneInfo.ejdwName;
                postParams.dw_3_id = checkSceneInfo.dw_3_id;
                postParams.dw_3_name = checkSceneInfo.dw_3_name;
                postParams.dw_4_id = checkSceneInfo.dw_4_id;
                postParams.dw_4_name = checkSceneInfo.dw_4_name;
                postParams.dw_5_id = checkSceneInfo.dw_5_id;
                postParams.dw_5_name = checkSceneInfo.dw_5_name;
                postParams.zyqId = checkSceneInfo.zyqId;
                postParams.zyqName = checkSceneInfo.zyqName;
            } else {
                console.log(' 左侧树下，添加 ')
                postParams.bmId = $('#dev_azdw1_select2').val();
                postParams.bmName = bmName;
                postParams.ejdwId = $('#dev_azdw2_select2').val();
                postParams.ejdwName = zyqName;
                postParams.dw_3_id = $('#dev_azdw3_select2').val();
                postParams.dw_3_name = dw_3_name;
                // postParams.dw_4_id = checkTreeInfo.dw_4_id;
                // postParams.dw_4_name = checkTreeInfo.dw_4_name;
                // postParams.dw_5_id = checkTreeInfo.dw_5_id;
                // postParams.dw_5_name = checkTreeInfo.dw_5_name;
                postParams.sceneId = $('#dev_azdw3_select2').val();
                postParams.parentId = 0;
                console.log('左侧树 postParams ================================== ')
            }
            console.log(postParams);
            $.ajax({
                method: "post",
                url: "/youtian/scene-category",
                data: JSON.stringify(postParams),
                dataType: "json",
                headers: {
                    "Content-Type": "application/json;charset=utf-8",
                },
                success: function (res) {
                    if (res.msg) {
                        $.modal.msgSuccess(res.msg);
                    }
                    // 提交成功，刷新表格，并把input框里的值，清空。
                    if (res.code == 0) {
                        $.treeTable.refresh();
                        $('#add-scene-dialog').modal('hide');
                    }
                }
            });
        }

        // 点击展示 编辑场景dialog
        function showEditorDialog(jsonObj) {
            $('#new-scene-name').val('')
            $('#current-scene-name').val(jsonObj.sceneName)
            $('#current-scene-id').val(jsonObj.sceneId)
            $('#editor-scene-dialog').modal('show');
        }

        //修改场景，点击保存
        function submitChangeSceneInfo() {
            var getName = $.trim($('#new-scene-name').val());
            if (getName == '') {
                console.log(`getName : ${getName}`)
                $.modal.msgError("请输入场景名称");
                return
            }
            // 发送修改请求
            $.ajax({
                method: "put",
                url: "/youtian/scene-category",
                data: JSON.stringify({
                    'sceneName': getName,
                    'sceneId': $('#current-scene-id').val()
                }),
                dataType: "json",
                headers: {
                    "Content-Type": "application/json;charset=utf-8",
                },
                success: function (res) {
                    if (res.msg) {
                        $.modal.msgSuccess(res.msg);
                    }
                    // 提交成功，刷新表格，并把input框里的值，清空。
                    if (res.code == 0) {
                        $.treeTable.refresh();
                        $('#editor-scene-dialog').modal('hide');
                    }
                }
            })
        }
        // 点击删除按钮
        function deleteScene(sceneId, sceneName) {
            var content = `您确认要删除”${sceneName}“，该场景吗？`;
            // 点击确认，删除对应的场景，并刷新表格
            $.modal.confirm(content, function (isOk) {
                console.log(`res,err ======== `)
                console.log(isOk)
                $.ajax({
                    method: "DELETE",
                    url: `/youtian/scene-category/${sceneId}`,
                    success: function (res) {
                        if (res.msg) {
                            $.modal.msgSuccess(res.msg);
                        }
                        // 提交成功，刷新表格，并把input框里的值，清空。
                        if (res.code == 0) {
                            $.treeTable.refresh();
                            $('#editor-scene-dialog').modal('hide');
                        }
                    }
                });
            });
        }

        function editPoint(jsonObj) {
            checkPointInfo = jsonObj;
            $('#new-point-name').val('')
            $('#current-point-name').val(jsonObj.pointName)
            $('#current-point-id').val(jsonObj.pointId)
            $('#editor-point-dialog').modal('show');
        }

        function submitChangePointInfo() {
            var getPointName = $.trim($('#new-point-name').val());
            if (getPointName == '') {
                console.log(`getName : ${getPointName}`)
                $.modal.msgError("请输入采集监测点名称");
                return;
            }
            // 获取当前的检测点 id 值
            var getPointId = $.trim($('#current-point-id').val());
            let params = {
                SourceTag: getPointId,
                Description: getPointName
            }
            console.log(getPointName);
            $.ajax({
                method: "post",
                // url:encodeURI(`/gzmx_tag_current/gzmx_tag_current/edit?SourceTag=${getPointId}&Description=${getPointName}`),
                url:'/gzmx_tag_current/gzmx_tag_current/edit',
                contentType: "application/json",
                data:JSON.stringify(params),
                success: function (res) {
                    if (res.msg) {
                        $.modal.msgSuccess(res.msg);
                    }
                    // 提交成功，刷新表格，并把input框里的值，清空。
                    if (res.code == 0) {
                        $.table.refresh();
                        $('#editor-point-dialog').modal('hide');
                    }
                }
            });
        }

        function deletePoint(pointInfoJson) {
            var content = `您确认要删除"${pointInfoJson.pointName ? pointInfoJson.pointName : "-"}"，该采集数据点位吗？`;
            // 点击确认，删除对应的场景，并刷新表格
            $.modal.confirm(content, function (isOk) {
                console.log(`res,err ======== `)
                console.log(isOk)
                let params = {
                    pointId: pointInfoJson.pointId,
                    sceneId: pointInfoJson.sceneId,
                    id: pointInfoJson.scenePointId,
                };
                $.ajax({
                    url: `/youtian/scene-point/remove`,
                    dataType: "json",
                    headers: { "Content-Type": "application/json" },
                    type: "post",
                    data: JSON.stringify(params),
                    success: function (res) {
                        if (res.msg) {
                            $.modal.msgSuccess(res.msg);
                        }
                        // 提交成功，刷新表格，并把input框里的值，清空。
                        if (res.code == 0) {
                            $.table.search();
                            $('#editor-point-dialog').modal('hide');
                            $('#myModal6').modal('hide');
                        }
                    }
                })
            });
        }

        function initAZDWselect(nextSelectIndex) {
            var params = {
                "jb": 1
            }
            nextSelectIndex = nextSelectIndex ? nextSelectIndex : 1;
            var $nextSelect = $(`#dev_azdw${nextSelectIndex}_select`);
            if (nextSelectIndex > 1) {
                params = {
                    fdwdm: $(`#dev_azdw${nextSelectIndex - 1}_select`).val()
                }
            }
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: params,
                success: function (res) {
                    console.log(' 生产点位 /gzmx_scdw/gzmx_scdw/list res');
                    console.log(res);
                    console.log($nextSelect);
                    var optionHTML = `<option value="">请选择</option>`
                    for (let i = 0; i < res.length; i++) {
                        optionHTML += `<option value="` + res[i].id + `">` + res[i].dwmc + `</option>`
                    }
                    $nextSelect.html(optionHTML);
                },
                error: function (error) {
                    $.modal.alertWarning(error);
                }
            });
        }
        function initAZDWselect1(nextSelectIndex) {
            var params = {
                "jb": 1
            }
            nextSelectIndex = nextSelectIndex ? nextSelectIndex : 1;
            var $nextSelect = $(`#dev_azdw${nextSelectIndex}_select1`);
            if (nextSelectIndex > 1) {
                params = {
                    fdwdm: $(`#dev_azdw${nextSelectIndex - 1}_select1`).val()
                }
            }
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: params,
                success: function (res) {
                    console.log(' 生产点位 /gzmx_scdw/gzmx_scdw/list res');
                    console.log(res);
                    console.log($nextSelect);
                    var optionHTML = `<option value="">请选择</option>`
                    for (let i = 0; i < res.length; i++) {
                        optionHTML += `<option value="` + res[i].id + `">` + res[i].dwmc + `</option>`
                    }
                    $nextSelect.html(optionHTML);
                },
                error: function (error) {
                    $.modal.alertWarning(error);
                }
            });
        }
        function initAZDWselect2(nextSelectIndex) {
            var params = {
                "jb": 1
            }
            nextSelectIndex = nextSelectIndex ? nextSelectIndex : 1;
            var $nextSelect = $(`#dev_azdw${nextSelectIndex}_select2`);
            if (nextSelectIndex > 1) {
                params = {
                    fdwdm: $(`#dev_azdw${nextSelectIndex - 1}_select2`).val()
                }
            }
            $.ajax({
                type: "post",
                url: "/gzmx_scdw/gzmx_scdw/list",
                data: params,
                success: function (res) {
                    console.log(' 生产点位 /gzmx_scdw/gzmx_scdw/list res');
                    console.log(res);
                    console.log($nextSelect);
                    var optionHTML = `<option value="">请选择</option>`
                    for (let i = 0; i < res.length; i++) {
                        optionHTML += `<option value="` + res[i].id + `">` + res[i].dwmc + `</option>`
                    }
                    $nextSelect.html(optionHTML);
                    console.log($nextSelect.html(optionHTML));
                },
                error: function (error) {
                    $.modal.alertWarning(error);
                }
            });
        }


        // 根据条件，筛选符合条件的监测点信息
        function queryPointSelect() {
            $("#point-select").html(`<option value="">请选择</option>`);
            let data = {
                deptId: null,
                ejdw_id: $("#dev_azdw2_select").val(),
                dw_3_id: $("#dev_azdw3_select").val(),
                dw_4_id: $("#dev_azdw4_select").val(),
                dw_5_id: $("#dev_azdw5_select").val()
            };
            console.log(data, "data");
            $.ajax({
                method: "POST",
                url: "/gzmx_tag/gzmx_tag/list",
                data: data,
                success: function (res) {
                    console.log(res, "data res");
                    var optionHTML = `<option value="">请选择</option>`;
                    for (let i = 0; i < res.rows.length; i++) {
                        var item = res.rows[i];
                        optionHTML += `<option value="${item.sourceTag}" data-lower="${item.min_value}" data-upper="${item.max_value}" >${item.description}</option>`
                    }
                    $("#point-select").html(optionHTML);
                    $("#upperLimit").val("")
                    $("#lowerLimit").val("")
                }
            });
        }

        function queryPointSelect1() {
            $("#point-select").html(`<option value="">请选择</option>`);
            let data = {
                deptId: null,
                ejdw_id: $("#dev_azdw2_select").val(),
                dw_3_id: $("#dev_azdw3_select").val(),
                dw_4_id: $("#dev_azdw4_select").val(),
                dw_5_id: $("#dev_azdw5_select").val()
            };
            console.log(data, "data");
            $.ajax({
                method: "POST",
                url: "/gzmx_tag/gzmx_tag/list",
                data: data,
                success: function (res) {
                    console.log(res, "data res");
                    var optionHTML = `<option value="">请选择</option>`;
                    for (let i = 0; i < res.rows.length; i++) {
                        var item = res.rows[i];
                        optionHTML += `<option value="${item.sourceTag}" data-lower="${item.min_value}" data-upper="${item.max_value}" >${item.description}</option>`
                    }
                    $("#point-select").html(optionHTML);
                    $("#upperLimit").val("")
                    $("#lowerLimit").val("")
                }
            });
        }
        function queryPointSelect2() {
            $("#point-select").html(`<option value="">请选择</option>`);
            let data = {
                deptId: null,
                ejdw_id: $("#dev_azdw2_select").val(),
                dw_3_id: $("#dev_azdw3_select").val(),
                dw_4_id: $("#dev_azdw4_select").val(),
                dw_5_id: $("#dev_azdw5_select").val()
            };
            console.log(data, "data");
            $.ajax({
                method: "POST",
                url: "/gzmx_tag/gzmx_tag/list",
                data: data,
                success: function (res) {
                    console.log(res, "data res");
                    var optionHTML = `<option value="">请选择</option>`;
                    for (let i = 0; i < res.rows.length; i++) {
                        var item = res.rows[i];
                        optionHTML += `<option value="${item.sourceTag}" data-lower="${item.min_value}" data-upper="${item.max_value}" >${item.description}</option>`
                    }
                    $("#point-select").html(optionHTML);
                    $("#upperLimit").val("")
                    $("#lowerLimit").val("")
                }
            });
        }

    </script>

</body>

</html>